﻿using System.Xml.Linq;
using Engine;
using GameEntitySystem;

namespace Game
{
    public class PositionWidget : CanvasWidget
    {
        public ComponentPlayer m_componentPlayer;

        public ButtonWidget m_positionButton;

        public ButtonWidget m_positionsButton;

        public ButtonWidget m_positionsButton1;

        public ButtonWidget m_positionsButton2;

        public ButtonWidget m_positionsButton3;

        public ButtonWidget m_positionsButton4;

        public SubsystemNK m_subsystemNK;

        public SubsystemNK subsystemHL;

        public ComponentMiner componentMiner;

        public ComponentHealth componentHealth;

        public PositionWidget(ComponentPlayer componentPlayer, SubsystemNK subsystemHL)
        {
            m_componentPlayer = componentPlayer;
            m_subsystemNK = subsystemHL;
            XElement node = ContentManager.Get<XElement>("Widgets/PositionWidget");
            LoadContents(this, node);
            m_positionButton = Children.Find<ButtonWidget>("m_positionButton");
            m_positionsButton = Children.Find<ButtonWidget>("m_positionsButton");
            m_positionsButton1 = Children.Find<ButtonWidget>("m_positionsButton1");
            m_positionsButton2 = Children.Find<ButtonWidget>("m_positionsButton2");
            m_positionsButton3 = Children.Find<ButtonWidget>("m_positionsButton3");
            m_positionsButton4 = Children.Find<ButtonWidget>("m_positionsButton4");
        }

        public override void Update()
        {
            string text = m_componentPlayer.ComponentBody.Position.X + "  ,  " + m_componentPlayer.ComponentBody.Position.Y + "  ,  " + m_componentPlayer.ComponentBody.Position.Z;
            string text2 = m_componentPlayer.PlayerData.SpawnPosition.X + "  ,  " + m_componentPlayer.PlayerData.SpawnPosition.Y + "  ,  " + m_componentPlayer.PlayerData.SpawnPosition.Z;
            if (m_positionButton.IsClicked)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("当前坐标:" + text, Color.White, blinking: false, playNotificationSound: false);
            }

            if (m_positionsButton.IsClicked)
            {
                m_componentPlayer.ComponentGui.DisplaySmallMessage("出生点坐标:" + text2, Color.White, blinking: false, playNotificationSound: false);
            }

            if (m_positionsButton1.IsClicked)
            {
                m_subsystemNK.CS2 = m_componentPlayer.ComponentBody.Position;
                m_componentPlayer.ComponentGui.DisplaySmallMessage("保存坐标", Color.White, blinking: false, playNotificationSound: false);
            }

            if (m_positionsButton2.IsClicked)
            {
                m_subsystemNK.CS3 = m_componentPlayer.PlayerData.SpawnPosition;
                m_componentPlayer.ComponentGui.DisplaySmallMessage("保存出生点坐标", Color.White, blinking: false, playNotificationSound: false);
            }

            if (m_positionsButton4.IsClicked)
            {
                m_componentPlayer.ComponentBody.Position = m_subsystemNK.CS3;
                m_componentPlayer.ComponentVitalStats.Stamina -= 0.5f;
                m_componentPlayer.ComponentHealth.Health -= 0.3f;
                m_componentPlayer.ComponentGui.DisplaySmallMessage("传送出生点坐标成功", Color.White, blinking: false, playNotificationSound: false);
            }

            if (m_positionsButton3.IsClicked)
            {
                if (m_componentPlayer.PlayerData.SpawnPosition.X != 0f)
                {
                    m_componentPlayer.ComponentBody.Position = m_subsystemNK.CS2;
                    m_componentPlayer.ComponentVitalStats.Stamina -= 0.5f;
                    m_componentPlayer.ComponentHealth.Health -= 0.3f;
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("传送成功", Color.White, blinking: true, playNotificationSound: false);
                }
                else
                {
                    m_componentPlayer.ComponentGui.DisplaySmallMessage("没有保存", Color.White, blinking: true, playNotificationSound: false);
                }
            }
        }
    }
}